/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ass1;

/**
 *
 * @author Dio
 */
public class Main {

    ProjModel pm;
    GridView gv;

    public Main() {
        pm = new ProjModel();
        gv = new GridView(this.pm);
    }

    /** This method will show the menu */
    public void showMenu() {

        while (true) {
      //show menu
        System.out.print( " === MENU ===\n" +
                " 1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n" +
                " 2. Set Number of vertical lanes  (V-street) [min 1, max 4]\n" +
                " 3. Set Probability of a car entering H-street [min 0, max 1]\n" +
                " 4. Set Probability of a car entering V-street [min 0, max 1]\n" +
                " 5. Run one simulation cycle\n" +
                " 6. Set and run number of simulation cycles [min 1, max 10]\n" +
                " 7. Exit menu\n");

        String userChoice = GetUserInput.getUserChoice("Enter your choice>");
        int userChoiceInt = Integer.parseInt(userChoice);
        System.out.println("After int conversion" + userChoiceInt);

        switch(userChoiceInt) {
            case 1 : System.out.println("Menu 1");
                     setNumHorLanes();
                break;
            case 2 : System.out.println ("Menu 2");
                     setNumVerLanes();
                break;
            case 3 : System.out.println ("Menu 3");
                     setHorProb();
                break;
            case 4 : System.out.println ("Menu 4");
                     setVerProb();
                break;
            case 5 : System.out.println ("Menu 5");
                     gv.GridMap('+', 1);
                break;
            case 6 : System.out.println ("Menu 6");
                    setTenCycle ();
                break;
            case 7 : System.out.println ("Menu 7");
                    System.out.println ("Thank You!");
                    System.exit (1);
                break;
            default : System.out.println ("Error in in entering menu choice");
        }
        }
    }
/** set number of horizontal lane*/
    public void setNumHorLanes () {
        String userChoice = GetUserInput.getUserChoice("Enter number of Horizontal Lanes : ");
        int userChoiceInt = Integer.parseInt(userChoice);
        int lowerLimit = 1;
        int upperLimit = 3;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
            System.out.println("Error in entering Horizontal Lanes");
            System.out.println("Please enter number above 1 and below 3.");
            showMenu();
        } else {//if user enter the correct input
            pm.setHorLanes(userChoiceInt);
            //let user set the number
          }
    }
/** set number of vertical lane*/
    public void setNumVerLanes () {
        String userChoice = GetUserInput.getUserChoice("Enter number of Vertical Lanes : ");
        int userChoiceInt = Integer.parseInt(userChoice);
        int lowerLimit = 1;
        int upperLimit = 4;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
            System.out.println("Error in entering Vertical Lanes");
            System.out.println("Please enter number above 1 and below 4.");
            showMenu();
        } else { //if user enter the correct input
            pm.setVerLanes(userChoiceInt);
            //let user set the number
          }
    }

/** set probability of horizontal car*/
    public void setHorProb () {
        String userChoice = GetUserInput.getUserChoice("Enter probability of Horizontal Lanes : ");
        double userChoiceInt = Double.parseDouble(userChoice);
        int lowerLimit = 0;
        int upperLimit = 1;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
            System.out.println("Error in entering probability of Horizontal Lanes");
            System.out.println("Please enter number between 0 and 1.");
            showMenu();
        } else {//if user enter the correct input
            pm.setHorProb(userChoiceInt);
            //let user set the number
          }
    }

/** set probability of vertical car*/
    public void setVerProb () {
        String userChoice = GetUserInput.getUserChoice("Enter probability of Vertical Lanes : ");
        double userChoiceInt = Double.parseDouble(userChoice);
        int lowerLimit = 0;
        int upperLimit = 1;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
            System.out.println("Error in entering probability of Vertical Lanes");
            System.out.println("Please enter number between 0 and 1.");
            showMenu();
        } else { //if user enter the correct input
            pm.setVerProb(userChoiceInt);
            //let user set the number
          }
    }

    public int showHorLanes() {
        return pm.getHorLanes();
    }

    public int showVerLanes() {
        return pm.getVerLanes();
    }
/** set cycle as user want*/
    public void setTenCycle () {
            String userChoice = GetUserInput.getUserChoice("Enter number of simulation cycles : ");
            int userChoiceInt = Integer.parseInt(userChoice);
            int lowerLimit = 1;
            int upperLimit = 10;
            if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
            System.out.println("Error in entering number of simulation cycles");
            System.out.println("Please enter number between 1 and 10.");
            } else {
                    for(int i=0; i<userChoiceInt; i++){
                    gv.GridMap('+', 1);
                    System.out.println("########################################");
                    }
            }
        showMenu ();
        }
}
